import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:get/get.dart';
import 'package:ball_lion/module/match/detail/zq_match_odds_detail_logic.dart';
import 'package:ball_lion/resources/colours.dart';
import 'package:ball_lion/resources/styles.dart';
import 'package:ball_lion/utils/date_time_utils.dart';
import 'package:ball_lion/utils/utils.dart';
import 'package:ball_lion/utils/widget_utils.dart';
import 'package:ball_lion/module/record/items/data_left_list.dart';
import 'package:ball_lion/widgets/loading/loading_widget.dart';

import 'package:ball_lion/widgets/base/wqs_text.dart';

class ZqMatchOddsDetailView extends StatelessWidget {
  ZqMatchOddsDetailView({super.key});

  final logic = Get.put(ZqMatchOddsDetailLogic());
  @override
  Widget build(BuildContext context) {
    return GetBuilder<ZqMatchOddsDetailLogic>(builder: (_) {
      return Scaffold(
          backgroundColor: Colours.main,
          appBar: Styles.appBar(
              backgroundColor: Colours.main,
              titleTextStyle:
                  const TextStyle(fontSize: 14, color: Colours.white),
              title: SizedBox(
                width: MediaQuery.of(context).size.width - 140,
                child:
                    Row(mainAxisAlignment: MainAxisAlignment.center, children: [
                  Expanded(
                      child: QsText(
                    logic.detail.info?.baseInfo?.homeName ?? "",
                  ).alignEnd),
                  QsText(" vs "),
                  Expanded(
                      child: QsText(
                    logic.detail.info?.baseInfo?.guestName ?? "",
                  ).alignStart)
                ]),
              ),
              leadingColor: Colours.white),
          body: Container(
            clipBehavior: Clip.antiAlias,
            decoration: const BoxDecoration(
                color: Colours.white,
                borderRadius: BorderRadius.only(
                    topRight: Radius.circular(10),
                    topLeft: Radius.circular(10))),
            child: LoadingWidget<int>(
              isLoading: false,
              data: logic.companyList[logic.typeIndex].length,
              child: () => Row(
                children: [
                  Container(
                    padding: const EdgeInsets.only(top: 16),
                    color: logic.selectIndex[logic.typeIndex] == 0
                        ? Colours.white
                        : Colours.greyF5F7FA,
                    child: DataLeftList(
                        logic.companyList[logic.typeIndex]
                            .map((e) => e.name ?? "")
                            .toList(),
                        logic.selectIndex[logic.typeIndex], (p0) {
                      logic.setSelectIndex(logic.typeIndex, p0);
                    }),
                  ),
                  Expanded(child: rightPage(logic.typeIndex))
                ],
              ),
            ),
          ));
    });
  }

  Widget rightPage(int i) {
    return Column(
      children: [
        DefaultTextStyle(
          style: TextStyle(fontSize: 12, color: Colours.grey66),
          child: Container(
            height: 40,
            padding: const EdgeInsets.symmetric(horizontal: 16),
            child: Row(
              children: [
                Expanded(
                    flex: 2, child: QsText(logic.headTypeList[i][0]).center),
                Expanded(
                    flex: 2, child: QsText(logic.headTypeList[i][1]).center),
                Expanded(
                    flex: 2, child: QsText(logic.headTypeList[i][2]).center),
                Expanded(flex: 3, child: QsText("时间").center)
              ],
            ),
          ),
        ),
        Expanded(
          child: LoadingWidget<int>(
            isLoading: false,
            data: logic.data[i].length,
            child: () => SingleChildScrollView(
                physics: const ClampingScrollPhysics(),
                child: Column(
                  children: List.generate(logic.data[i].length, (index) {
                    var entity = logic.data[i][index];
                    var data =
                        logic.formSingleLine(logic.data[i][index].data ?? []);
                    return Stack(
                      children: [
                        DefaultTextStyle(
                          style: TextStyle(fontSize: 12),
                          child: Container(
                            height: 44,
                            margin: const EdgeInsets.symmetric(horizontal: 16),
                            decoration: const BoxDecoration(
                                border: Border(
                                    bottom: BorderSide(
                                        color: Colours.greyEE, width: 0.5))),
                            child: Row(
                              children: [
                                Expanded(
                                    flex: 2,
                                    child: (entity.closed == "封"
                                            ? QsText("-")
                                            : data[0])
                                        .center),
                                Expanded(
                                    flex: 2,
                                    child: (i == 1 || i == 3
                                            ? QsText(entity.line ?? "")
                                            : entity.closed == "封"
                                                ? QsText("封")
                                                : data[1])
                                        .center),
                                Expanded(
                                    flex: 2,
                                    child: (entity.closed == "封"
                                            ? QsText("-")
                                            : data[2])
                                        .center),
                                Expanded(
                                    flex: 3,
                                    child: QsText(
                                            entity.updateTime.noValue == true
                                                ? ""
                                                : DateTime.parse(
                                                        entity.updateTime!)
                                                    .formatedString(
                                                        "MM/dd HH:mm"),
                                            color: Colours.grey99)
                                        .center)
                              ],
                            ),
                          ),
                        ),
                        if (entity.beginFlag == true)
                          Align(
                              alignment: Alignment.topCenter,
                              child: _beginFlag())
                      ],
                    );
                  }),
                ).paddingOnly(bottom: 50)),
          ),
        )
      ],
    );
  }

  Widget _beginFlag() {
    return Container(
      height: 14,
      width: 36,
      alignment: Alignment.center,
      decoration: const BoxDecoration(
          color: Colours.main,
          borderRadius: BorderRadius.vertical(bottom: Radius.circular(4))),
      child: QsText("赛前", color: Colours.white, fontSize: 10),
    );
  }
}
